package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

public interface OrderMapper {
    //新增订单
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into orders " +
            "(number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark," +
            "phone, address, user_name, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number, tableware_status)\n" +
            "values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod}," +
            "#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{userName}, #{consignee}," +
            "#{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})")
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> page(OrdersPageQueryDTO ordersPageQueryDTO);


    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 统计订单数量
     * @param
     * @return
     */
    @Select("select count(id)from orders where status=#{status}")
    Integer countStatus(Integer status);
}
